import { useState } from "react";
import { Button, message, Form, Input, Space } from "antd";
import { useModel } from "umi";

const EditApplicationTypeForm = ({ item, reloadData }) => {
    const { remoteData } = useModel("global");
    const { onCloseGlobalModal } = useModel("global.modal");

    const [submitLoading, setSubmitLoading] = useState(false);
    const [form] = Form.useForm();

    const onFinish = async (values) => {
        setSubmitLoading(true);
        let res = await remoteData({
            object: "bnt-application-resource-center-service",
            serviceName: "/developer/application/updateType",
            params: {
                appUuid: item.appUuid,
                appType: item.appType,
                data: values,
            },
        });
        if (res) {
            message.success("成功更新应用客户端信息");
            form.resetFields();
            reloadData();
            onCloseGlobalModal();
        }
        setSubmitLoading(false);
    };

    return (
        <div style={{ padding: "0 30px 0 30px" }}>
            <Form form={form} onFinish={onFinish} layout="vertical" initialValues={item}>
                <Form.Item label="路由路径" name="appPath">
                    <Input />
                </Form.Item>

                <Form.Item label="代码网址" name="appGiturl">
                    <Input />
                </Form.Item>

                <Form.Item label="Git地址" name="appGitlab">
                    <Input />
                </Form.Item>

                <Form.Item label="客户端描述" name="appDesc">
                    <Input.TextArea />
                </Form.Item>

                <Form.Item style={{ textAlign: "center" }}>
                    <Space>
                        <Button loading={submitLoading} type="primary" htmlType="submit">
                            保存应用客户端信息
                        </Button>
                        <Button loading={submitLoading} htmlType="button" onClick={() => form.resetFields()}>
                            重置
                        </Button>
                    </Space>
                </Form.Item>
            </Form>
        </div>
    );
};

export default EditApplicationTypeForm;
